<template>
  <avue-crud
    :option="option"
    :table-loading="loading"
    :data="data"
    ref="crud"
    v-model="form"
    :permission="permissionList"
    :search.sync="search"
    @row-del="rowDel"
    :before-open="beforeOpen"
    :page="page"
    @search-change="searchChange"
    @search-reset="searchReset"
    @selection-change="selectionChange"
    @current-change="currentChange"
    @size-change="sizeChange"
    @refresh-change="refreshChange"
    @on-load="onLoad"
  >
    <template #menuLeft>
      <div class="flex-start">
        <el-date-picker
          size="small"
          v-model="searchDate"
          type="daterange"
          class="m-r-10"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="refreshChange"
        />
        <el-input
          placeholder="请输入活动名称"
          size="small"
          v-model="query.couponName"
          style="width: 250px"
          suffix-icon="el-icon-search"
          @change="refreshChange"
        />
      </div>
    </template>
    <template #menuRight>
      <el-button type="primary" size="small">报表下载</el-button>
    </template>
  </avue-crud>
</template>

<script>
import { getList } from "@/api/marketing-management/marketing-statistics-apostle-rebate";
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      form: {},
      roleBox: false,
      excelBox: false,
      loading: true,
      selectionList: [],
      query: {
        startDate: "",
        endDate: "",
      },
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      props: {
        label: "title",
        value: "key",
      },
      option: {
        columnBtn: false,
        refreshBtn: false,
        height: "auto",
        calcHeight: 310,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        viewBtn: false,
        addBtn: false,
        menu: false,
        align: "center",
        column: [
          {
            label: "加注单号",
            prop: "recordCode",
            span: 24,
          },
          {
            label: "活动名称",
            prop: "couponName",
            span: 24,
          },
          {
            label: "券面值（元）",
            prop: "couponAmount",
            span: 24,
          },
          {
            label: "使用门槛（元）",
            prop: "couponOrderAmount",
            span: 24,
          },
          {
            label: "加注机编号",
          },
          {
            label: "加注站名称",
            prop: "siteName",
          },
          {
            label: "优惠券类型",
            prop: "drawType",
            width: 140,
            overHidden: true,
            type: "select",
            dicData: [
              { label: "直接领取", value: 0 },
              { label: "加注领取", value: 1 },
            ],
            span: 24,
          },
          { label: "区域", prop: "" },
          { label: "加注时间", prop: "finishTime" },
        ],
      },
      data: [],
      searchDate: null,
    };
  },
  computed: {
    ...mapGetters(["userInfo", "permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.user_add, false),
        viewBtn: this.vaildData(this.permission.user_view, false),
        delBtn: this.vaildData(this.permission.user_delete, false),
        editBtn: this.vaildData(this.permission.user_edit, false),
      };
    },
  },
  methods: {
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      if (this.searchDate) {
        this.query.startDate = this.searchDate[0];
        this.query.endDate = this.searchDate[1];
      } else {
        this.query.startDate = "";
        this.query.endDate = "";
      }
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
    },
  },
};
</script>

<style></style>
